<template>
    <div class="home">
        <img class="img-1" src="@/assets/图层 65.png" alt="">
        <img class="img-2" src="@/assets/图层 62.png" alt="">
        <img class="img-3 animate__animated animate__rubberBand" src="@/assets/title.png" alt="">
        <img class="img-4" src="@/assets/time.png" alt="">
        <img class="img-5" src="@/assets/左边树.png" alt="">
        <img class="img-6" src="@/assets/右边树.png" alt="">

        <div class="progress">
            <div class="active" :style="`width: ${progress}%;`"></div>
            <div class="txt">正在加载{{ progress }}%</div>
        </div>


    </div>
</template>

<script>
// @ is an alias to /src

export default {
    name: 'HomeView',
    components: {
    },
    data() {
        return {
            isShow: false,
            progress: 0,
            imageUrls: [
                require('@/assets/图层 65.png'),
                require('@/assets/巫溪活动_03.png'),
                require('@/assets/巫溪活动_05.png'),
                require('@/assets/巫溪活动_06.png'),
                require('@/assets/巫溪活动_07.png'),
                require('@/assets/下面云.png'),
                require('@/assets/图层 78.png'),
                require('@/assets/图层 77.png'),
                require('@/assets/图层 9 拷贝.png'),
                require('@/assets/图层 3 拷贝.png'),
                require('@/assets/图片1.png'),
                require('@/assets/图片2.png'),
                require('@/assets/图片3.png'),
                require('@/assets/图片4.png'),
                require('@/assets/图片5.png'),
                require('@/assets/图片6.png'),
                require('@/assets/图片7.png'),
                require('@/assets/图片8.png'),
                require('@/assets/图片9.png'),
                require('@/assets/图片10.png'),
                require('@/assets/图片11.png'),
                require('@/assets/图片12.png'),
                require('@/assets/图片13.png'),
                require('@/assets/图片14.png'),
                require('@/assets/图片15.png'),
  
            ],
            loadedCount: 0,
        }
    },
    mounted() {
        this.loadImages().then(()=> {
           
        }); 
    },
    methods: {
        async loadImages() {
            const imagePromises = this.imageUrls.map(url => {
                return new Promise((resolve, reject) => {
                    const image = new Image();
                    image.onload = () => {
                        this.loadedCount++;
                        this.progress = ((this.loadedCount / this.imageUrls.length) * 100).toFixed(0);
                        if (this.loadedCount === this.imageUrls.length) {
                            this.allImagesLoaded = true;
                            localStorage.setItem('allImagesLoaded', '1');
                            this.$router.push('/')
                        }
                        resolve();
                    };
                    image.onerror = error => {
                        console.error(`Error loading image: ${url}`, error);
                        reject();
                    };
                    image.src = url;
                });
            });

            try {
                await Promise.all(imagePromises);
            } catch (error) {
                console.error('Error loading images', error);
                // 可以选择在这里处理加载错误的情况，例如重试或显示错误消息  
            }
        },
    },
}
</script>

<style lang="less" scoped>
.progress {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);
    background: #fff;
    border: 1px solid #285853;
    height: 8px;
    width: 80%;
    border-radius: 20px;

    .txt {
        position: absolute;
        width: 100%;
        text-align: center;
        bottom: -.5rem;
        left: 0;
        font-size: .24rem;
    }

    .active {
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        background: #285853;
        width: 10%;
        border-radius: 20px;
    }
}

@keyframes ren2 {
    0% {
        transform: rotate(0deg) translateY(-0.2rem);
        opacity: 1;

    }

    50% {
        transform: rotate(5deg) translateY(0rem);
        opacity: 1;

    }

    100% {
        transform: rotate(0deg) translateY(-0.2rem);
        opacity: 1;

    }
}

.img-11-1 {
    opacity: 1;
    animation: ren2 4s linear infinite !important;
}

img {
    display: block;
}

.ad-05s {
    animation-delay: .5s;
}

.ad-1s {
    animation-delay: 1s;
}

.ad-2s {
    animation-delay: 1.5s;
}

.ad-3s {
    animation-delay: 2s;
}

.ad-4s {
    animation-delay: 2.5s;
}

.home {
    /* Permalink - use to edit and share this gradient: https://colorzilla.com/gradient-editor/#e5f2d2+0,aed5d3+100 */
    position: relative;
    padding-top: 1rem;
    box-sizing: border-box;
    min-height: 100vh;
    overflow: hidden;
}

.bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    overflow: hidden;

    @keyframes btn {
        0% {
            transform: translateX(-50%) scale(.9);
            opacity: 1;
        }

        50% {
            transform: translateX(-50%) scale(1);
            opacity: 1;
        }

        100% {
            transform: translateX(-50%) scale(.9);
            opacity: 1;
        }

    }

    .img-13 {
        width: 3.7rem;
        position: absolute;
        bottom: .5rem;
        left: 50%;
        transform: translateX(-50%);
        opacity: 0;
        animation: btn 2s 3s infinite;
    }

    .img-12 {
        width: 7.5rem;
        display: block;
    }
}

@keyframes ren {
    0% {
        transform: scale(0) translateY(-4rem) translateX(4rem);
        z-index: -1;
        opacity: 0;
    }

    50% {
        transform: scale(.5) translateY(-2rem) translateX(2rem);
        z-index: 1;
        opacity: 1;
    }

    100% {
        transform: scale(1) translateY(0rem) translateX(0rem);
        z-index: 2;
        opacity: 1;
    }
}

.img-11 {
    width: 2.69rem;
    position: absolute;
    top: 7rem;
    right: .2rem;
    opacity: 0;
    animation: ren 1s 3s linear forwards;
}

@keyframes yunwu {
    0% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

.img-10 {
    width: 7.5rem;
    position: absolute;
    right: 0;
    top: 8.65rem;
    opacity: 0;
    animation: yunwu 1s 3.5s linear forwards;
}

.img-9 {
    width: 4.43rem;
    position: absolute;
    top: 6.4rem;
    right: 0;
}

.img-8 {
    width: 5.72rem;
    position: absolute;
    right: 0;
    top: 4.5rem;
}

.img-7 {
    width: 7.5rem;
    left: 0;
    position: absolute;
    top: 3.8rem;
    z-index: 1;
}

.img-6 {
    width: .58rem;
    position: absolute;
    right: 0;
    top: 2.27rem;
}

.img-5 {
    width: .99rem;
    position: absolute;
    left: 0;
    top: 2.27rem;
    z-index: 2;
}

.img-4 {
    display: block;
    margin: .35rem auto 0;
    width: 4.75rem;
}

.img-3 {
    width: 7.13rem;
    display: block;
    margin: auto;

}

.img-1 {
    position: absolute;
    top: -.4rem;
    left: 0;
    width: 1.88rem;
}

.img-2 {
    position: absolute;
    top: -1.2rem;
    right: 0;
    width: 2.02rem;
}
</style>